#ifndef DRAWINGAREA_HPP
#define DRAWINGAREA_HPP

#include <QWidget>

#include "Model.hpp"

class MainWindow;

class DrawingArea : public QWidget
{
public:
    explicit DrawingArea(QWidget *parent = 0);
    ~DrawingArea();

    void paintEvent(QPaintEvent *);
    void repaint();
    void setModel(Model* model);
    void mousePressEvent(QMouseEvent* e);
    void mouseMoveEvent(QMouseEvent * e);
    void mouseReleaseEvent(QMouseEvent* e);

    void setZoom(double z);

private:
    Model* _model;
    QPixmap _nodeIcons[Node::NB_NODE_TYPE];
    QString _relationSymbols[Node::NB_RELATION_TYPE];
    double _zoom;
    double _ratio;
    void drawSubTree(QPainter& painter, Node* const node,
                     int xRep, int yRep);
    void addNewNode();
    int minX  , minY , maxX, maxY ;

    enum State
    {
        IDLE,
        CLICK_OR_DRAG,
        DRAGGING
    };
    State _state;
    QPoint _pointerPosition;
    QPoint* _newNodePos;
    QPoint _closestNodePos;
    Node* _closestNode;
};

#endif // DRAWINGAREA_HPP
